﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Fotobanka
{
    public partial class ListUzivatelu : System.Web.UI.Page
    {
        LoginInfo li;
        UserManager um;
        protected void Page_Load(object sender, EventArgs e)
        {
            li = (LoginInfo)Session["logged_user_id"];
            um = new UserManager();
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (((UserObject)e.Row.DataItem).Role == 1)
                {
                    ((LinkButton)e.Row.FindControl("LinkButton1")).Visible = false; ;

                }

                foreach (DataControlField dcf in ((GridView)sender).Columns)
                {
                    if (dcf.ToString() == "CommandField")
                    {
                        if (((CommandField)dcf).ShowDeleteButton == true)
                        {
                            e.Row.Cells[((GridView)sender).Columns.IndexOf(dcf)].Attributes
                            .Add("onclick", "return confirm(\"Opravdu chcete smazat?\")");
                        }
                    }
                    else if (dcf.SortExpression == "Authorization")
                    {

                        if (e.Row.Cells[((GridView)sender).Columns.IndexOf(dcf)].Text == "0")
                            e.Row.Cells[((GridView)sender).Columns.IndexOf(dcf)].Text = "Ne";
                        else
                            e.Row.Cells[((GridView)sender).Columns.IndexOf(dcf)].Text = "Ano";
                    }
                    else if (dcf.SortExpression == "GalleryAdmin")
                    {

                        if (e.Row.Cells[((GridView)sender).Columns.IndexOf(dcf)].Text == "0")
                            e.Row.Cells[((GridView)sender).Columns.IndexOf(dcf)].Text = "Ne";
                        else
                            e.Row.Cells[((GridView)sender).Columns.IndexOf(dcf)].Text = "Ano";
                    } 
                }
            }
        }

        protected void GridView1_DataBinding(object sender, EventArgs e)
        {
            
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Admintrue")
            {
                um.SetAsAdmin(Convert.ToInt32(e.CommandArgument));
            }
        }
    }
}
